<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>委托信息</title>
<script src="${ctx}/static/selectWin/userSelector.js"
	type="text/javascript"></script>
<script type="text/javascript">
	var $grid, $userSelector;
	var selectTableRow;//选中的行数据
	$(function() {
		$userSelector = $("#attorney").comboselector(userSelectOpts);
		$('#processId').combobox({
			url : '${ctx}/bpm/process/bpmProcessCombobox',
			method : 'get',
			editable : false,
			idField : 'value',
			textField : 'text',
			dataPlain : true,
			panelWidth : 350
		});
		$grid = $("#grid").datagrid(
				$.extend(datagridOption, {
					url : "${ctx}/bpm/delegateInfo/dataGrid",
					columns : [ [
							{
								field : 'ck',
								checkbox : true
							},
							{
								field : 'assignee',
								title : '委托人',
								sortable : true,
								formatter : function(value, row, index) {
									return value ? value.trueName : "";
								}
							},
							{
								field : 'attorney',
								title : '被委托人',
								sortable : true,
								formatter : function(value, row, index) {
									return value ? value.trueName : "";
								}
							},
							{
								field : 'startTime',
								title : '开始时间',
								sortable : true
							},
							{
								field : 'endTime',
								title : '截止时间',
								sortable : true
							},
							{
								field : 'bpmProcess',
								title : '流程信息',
								sortable : true,
								formatter : function(value, row, index) {
									return !value ? "" : value.name;
								}
							},
							{
								field : 'status',
								title : '是否有效',
								sortable : true,
								formatter : function(value, row, index) {
									return '<input class="easyui-switchbutton" ' + (value == 1 ? "checked" : "")
											+ ' data-options="readonly:true,onText:\'是\',offText:\'否\'">';
								}
							} ] ]
				}));
		$grid.datagrid('enableFilter', [ {
			field : 'assignee',
			searchField : 'assignee.trueName'
		}, {
			field : 'attorney',
			searchField : 'attorney.trueName'
		}, {
			field : 'startTime',
			type : 'datebox',
			javaType : 'D',
			op : [ 'EQ', 'NEQ', 'GT', 'LT', 'GTE', 'LTE', 'ISNULL', 'NOTNULL' ]
		}, {
			field : 'endTime',
			type : 'datebox',
			javaType : 'D',
			op : [ 'EQ', 'NEQ', 'GT', 'LT', 'GTE', 'LTE', 'ISNULL', 'NOTNULL' ]
		}, {
			field : 'bpmProcess',
			searchField : 'bpmProcess.name'
		}, {
			field : 'status',
			type : 'combobox',
			javaType : 'I',
			options : {
				panelHeight : 'auto',
				data : [ {
					value : '',
					text : '全部'
				}, {
					value : '1',
					text : '开启'
				}, {
					value : '2',
					text : '关闭'
				} ],
				onChange : function(value) {
					if (value == '') {
						$("#grid").datagrid('removeFilterRule', 'status');
					} else {
						$("#grid").datagrid('addFilterRule', {
							field : 'status',
							op : 'EQ',
							value : value
						});
					}
					$("#grid").datagrid('doFilter');
				}
			}
		} ]);

		$("#statusSB").switchbutton({
			onText : "是",
			offText : "否",
			checked : true,
			onChange : function(checked) {
				if (checked) {
					$("#status").val(1);
				} else {
					$("#status").val(2);
				}
			}
		});

		$("#add").click(function() {
			$("#fm").form("clear");
			$('#fm').form('load', {
				status : 1
			});
			$("#statusSB").switchbutton('check');
			$("#dlg").dialog("open").dialog("setTitle", "新增委托信息单");
		});
		$("#edit").click(
				function() {
					var rowData = $grid.datagrid("getSelected");
					if (rowData == null) {
						$.messager.show({
							msg : "您未选中行，无法编辑",
							icon : "warning",
							position : "bottomRight"
						});
					} else {
						$("#dlg").dialog("open").dialog("setTitle", "编辑委托信息");
						$("#fm").form("load", $.extend(rowData, {
							processId : rowData.bpmProcess.id
						}));
						$("#statusSB").switchbutton(rowData.status == 1 ? "check" : "uncheck");
						$userSelector.comboselector("setValue", rowData.attorneyUser ? rowData.attorneyUser.id : "")
								.comboselector("setText", rowData.attorneyUser ? rowData.attorneyUser.trueName : "");
					}
				});
		$("#delete").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (rowData == null) {
				$.messager.show({
					msg : "您未选中行，无法删除",
					icon : "warning",
					position : "bottomRight"
				});
			} else {
				$.messager.confirm("您确定要进行该操作？", function(c) {
					if (c) {
						$.get("${ctx}/bpm/delegateInfo/delete/" + rowData.id, function(result) {
							$.messager.show({
								msg : result.msg,
								icon : "info",
								position : "bottomRight"
							});
							if (result.success) {
								$grid.datagrid("deleteRow", rowData);
							}
						}, 'json');
					}
				});
			}
		});
		$("#excelImport").click(function() {
			$.easyui.importor.showImportor({
				importNo : "",
				onExportSuccess : function(file, data) {
					$grid.datagrid('load');
				}
			});
		});
		$("#excelExport").click(
				function() {
					window.parent.location.href = "${ctx}/bpm/delegateInfo/excelExport?"
							+ $.param($grid.datagrid('options').queryParams);
				});
	});

	function fn_save() {
		$("#fm").form("submit", {
			url : "${ctx}/bpm/delegateInfo/update",
			success : function(data) {
				$grid.datagrid("load");
				$.messager.show({
					msg : data.msg,
					icon : "info",
					position : "bottomRight"
				});
				$("#dlg").dialog('close');
			}
		});
	}
</script>
</head>

<body>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid">
		</table>
	</div>
	<div id="tt" class="row">
		<div class="col-md-12">
			<shiro:hasPermission name="bpmDelegateInfo:update">
				<button id="add" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-plus"></span> 新增
				</button>
				<button id="edit" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-pencil"></span> 编辑
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="bpmDelegateInfo:delete">
				<button id="delete" type="button" class="btn btn-danger">
					<span class="glyphicon glyphicon-minus"></span> 删除
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="bpmDelegateInfo:import">
				<button id="excelImport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-open"></span> Excel导入
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="bpmDelegateInfo:export">
				<button id="excelExport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-save"></span> Excel导出
				</button>
			</shiro:hasPermission>
		</div>
	</div>
	<shiro:hasPermission name="bpmDelegateInfo:update">
		<div id="dlg" class="easyui-dialog"
			style="width: 370px; height: 310px; padding: 10px 20px"
			data-options="resizable:true,modal:true, buttons:'#dlg-btn',closed:true">
			<form id="fm" method="post">
				<input type="hidden" name="id" />
				<table id="tbl">
					<tr>
						<td><label>流程信息ID:</label></td>
						<td><input id="processId" name="processId"
							class="easyui-validatebox" data-options="required: false"></td>
					</tr>
					<tr>
						<td><label>被委托人:</label></td>
						<td><input id="attorney" name="attorney"
							class="easyui-validatebox" data-options="required: false"></td>
					</tr>
					<tr>
						<td><label>开始时间:</label></td>
						<td><input name="startTime" class="easyui-datebox"
							data-options="required: false"></td>
					</tr>
					<tr>
						<td><label>截止时间:</label></td>
						<td><input name="endTime" class="easyui-datebox"
							data-options="required: false"></td>
					</tr>
					<tr>
						<td><label>是否启用:</label></td>
						<td><input id="radio1" name="status" type="hidden"> <input
							id="statusSB"></td>
					</tr>
				</table>
			</form>
			<div id="dlg-btn">
				<button id="add" type="button" class="btn btn-primary"
					onclick="fn_save();">
					<span class="glyphicon glyphicon-ok"></span> 保存
				</button>
				<button id="edit" type="button" class="btn btn-primary"
					onclick="$('#dlg').dialog('close');">
					<span class="glyphicon glyphicon-remove"></span> 取消
				</button>
			</div>
		</div>
	</shiro:hasPermission>
</body>
</html>
